#to fill the data in rea-comp based on the reaction equations

def reacomp(request):
   reas=Reaction.objects.all()
   Rea_comp.objects.all().delete() #clear contents in the table
   for rea in reas:
    r=rea.reactionid 
    i=i+1
    a=rea.eq_in_id.split('=')
    subs=a[0].strip().split('+')
    for sub in subs:
        b=sub.strip().split(' ') #coefficient and compound ID seperated by space
        if len(b)==1:
            sto=-1.0
            species=str(b[0])
        else:
            sto=-float(b[0])
            species=str(b[1])
    rc=Rea_comp()
    rc.reaction=rea
    rc.compound=Compound.objects.get(compoundid=species)
    rc.coefficient=str(sto)
    rc.save()
    pros=a[1].strip().split('+')
    for pro in pros:
        b=pro.strip().split(' ')
        if len(b)==1:
            sto=1.0
            species=str(b[0])
        else:
            sto=float(b[0])
            species=str(b[1])
    rc=Rea_comp()
    rc.reaction=rea
    rc.compound=Compound.objects.get(compoundid=species)
    rc.coefficient=str(sto)
    rc.save()
    return render_to_response('thanks.html', locals())
